<?php

class Euso_ObjectRef
{
	protected $_objectClassIdName = NULL;
	protected $_objectId = NULL;
	protected $_objectIdName = NULL;
	protected $_objectInstance = NULL;


	public function __construct($objClassIdName = NULL, $objId = NULL, $objIdName = NULL)
	{
		$this->_objectClassIdName = $objClassIdName;
		$this->_objectId = $objId;
		$this->_objectIdName = $objIdName;
	}


	public function setObjectClassIdName($objClassIdName = NULL)
	{
		if ($this->_objectClassIdName !== $objClassIdName) {
			$this->_objectClassIdName = $objClassIdName;
			$this->_objectInstance = NULL;
		}
		return $this;
	}
	public function setObjectId($objId = NULL)
	{
		$objId = intval($objId);
		if ($this->_objectId !== $objId) {
			$this->_objectId = $objId;
			$this->_objectInstance = NULL;
		}
		return $this;
	}
	public function setObjectIdName($objIdName = NULL)
	{
		if ($this->_objectIdName !== $objIdName) {
			$this->_objectIdName = $objIdName;
			$this->_objectInstance = NULL;
		}
		return $this;
	}
	public function setObjectInstance($objInst = NULL)
	{
		$this->_objectInstance = $objInst;
		return $this;
	}

	public function getObjectClassIdName()
	{
		return $this->_objectClassIdName;
	}
	public function getObjectId()
	{
		return $this->_objectId;
	}
	public function getObjectIdName()
	{
		return $this->_objectIdName;
	}
	public function getObjectInstance()
	{
		if ($this->_objectInstance === NULL) {
			$this->_objectInstance = Euso_Object::getInstance($this->objectClassIdName,
				$this->objectId, $this->objectIdName);
		}
		return $this->_objectInstance;
	}


    public function __set($name, $value)
    {
        $method = 'set' . ucfirst($name);
        $this->$method($value);
    }
    public function __get($name)
    {
        $method = 'get' . ucfirst($name);
        return $this->$method();
    }
}
